package com.harry.example1;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
//@EnableDiscoveryClient
@MapperScan(basePackages = {"com.harry.example1.mapper","com.gitee.sunchenbin.mybatis.actable.dao"} )
@ComponentScan("com.gitee.sunchenbin.mybatis.actable.manager.*")
public class Example1Application {


    public static void main(String[] args) {
        SpringApplication.run(Example1Application.class,args);
    }


    @RestController
    public class EchoController {
        @Autowired
        private RestTemplate restTemplate;

        @GetMapping(value = "/echo/{string}")
        public String echo(@PathVariable String string) {
            return "Hello Nacos Discovery " + string;
        }

        @GetMapping("/testRemote")
        public String testRemote(){
            String url = "http://example2/testRemote";
            ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
            return forEntity.getBody();
        }
    }



    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder){
        RestTemplate build = restTemplateBuilder.build();
        return build;
    }
}



